import { Body, Controller, Post, Session, UploadedFile, UseGuards, UseInterceptors, UsePipes, ValidationPipe } from '@nestjs/common';
import { BusinessService } from './business.service';
import {
    AuditDto,
    AuditInvoiceFeedetDto,
    AuditInvoicePayDto,
    BusinessReportDto,
    BusiReportDto,
    CategoryDto,
    CurrencyDto,
    ExchangeRateDto,
    FeeCodDto,
    FeeCodModDto,
    FeedetDto,
    FeeEleDto,
    FeeEleLovDto,
    FeeModDto,
    FeeModEleDto,
    
    
    FeeReportDefineDto,
    
    
    FeeTypDto,
    InitLovDto,
    InvoiceDto,
    LeaseFeeReportDto,
    LeaseFeeUsdInvoiceDto,
    PayDto,
    PrePayDto,
    ProtocolDto,
    ProtocolRatDto,
    queryElesByFeeModDto,
    queryModsByFeeCodDto,
} from './dto/create-business.dto';
import {
    UpdateCategoryDto,
    UpdateCurrencyDto,
    UpdateExchangeRateDto,
    UpdateFeeCodDto,
    UpdateFeeCodModDto,
    UpdateFeedetDto,
    UpdateFeeEleDto,
    UpdateFeeEleLovDto,
    UpdateFeeModDto,
    UpdateFeeModEleDto,
   UpdateFeeTypCodDto,
   /*  UpdateFeeTypCodDto, */
    UpdateFeeTypDto,
    UpdateInvoiceDto,
    UpdatePayDto,
    UpdatePrePayDto,
    UpdateProtocolDto,
    UpdateProtocolRateDto,
} from './dto/update-business.dto';
import {
    DeleteDto,
    DeleteStrPrimaryDto,
    SqlQueryDto,
} from '@/common/type/app.dto';
import { omit } from 'lodash';
import { AuthGuard } from '@/common/guard/auth.guard';
import { FileInterceptor } from '@nestjs/platform-express';
import { UpdateFeeReportDefineDto } from '@/basedata/dto/update-basedatum.dto';

@Controller('business')
@UseGuards(AuthGuard)
export class BusinessController {
    constructor(private readonly businessService: BusinessService) {}
    @Post('protocolcreate')
    async createprotocol(@Body() data: ProtocolDto) {
        return await this.businessService.createProtocol(data);
    }

    @Post('protocolupdate')
    async updateprotocol(@Body() data: UpdateProtocolDto) {
        return await this.businessService.updateProtocol(data);
    }

    @Post('protocoldelete')
    async deleteprotocol(@Body() data: DeleteStrPrimaryDto) {
        return await this.businessService.deleteProtocol(data);
    }

    @Post('protocolquery')
    async queryprotocol(@Body() data: SqlQueryDto) {
        return await this.businessService.queryProtocol(data);
    }

    @Post('feeelecreate')
    async createfeeele(@Body() data: FeeEleDto) {
        return await this.businessService.createFeeEle(data);
    }

    @Post('feeeleupdate')
    async updatefeeele(@Body() data: UpdateFeeEleDto) {
        return await this.businessService.updateFeeEle(data);
    }

    @Post('feeeledelete')
    async deletefeeele(@Body() data: DeleteStrPrimaryDto) {
        return await this.businessService.deleteFeeEle(data);
    }

    @Post('feeelequery')
    async queryfeeele(@Body() data: SqlQueryDto) {
        return await this.businessService.queryFeeEle(data);
    }
    @Post('feeelelovcreate')
    async createfeeelelov(@Body() data: FeeEleLovDto) {
        return await this.businessService.createFeeEleLov(data);
    }
    @Post('feeelelovupdate')
    async updatefeeelelov(@Body() data: UpdateFeeEleLovDto) {
        return await this.businessService.updateFeeEleLov(data);
    }
    @Post('feeelelovdelete')
    async deletefeeelelov(@Body() data: DeleteStrPrimaryDto) {
        return await this.businessService.deleteFeeEleLov(data);
    }
    @Post('feeelelovquery')
    async queryfeeelelov(@Body() data: SqlQueryDto) {
        return await this.businessService.queryFeeEleLov(data);
    }
    @Post('feeelelovinit')
    async initfeeelelov(@Body() data: InitLovDto) {
        return await this.businessService.initLov(data);
    }
    @Post('feemodcreate')
    async createfeemod(@Body() data: FeeModDto) {
        return await this.businessService.createFeeMod(data);
    }
    @Post('feemodupdate')
    async updatefeemod(@Body() data: UpdateFeeModDto) {
        return await this.businessService.updateFeeMod(data);
    }

    @Post('feemoddelete')
    async deletefeemod(@Body() data: DeleteStrPrimaryDto) {
        return await this.businessService.deleteFeeMod(data);
    }

    @Post('feemodquery')
    async queryfeemod(@Body() data: SqlQueryDto) {
        return await this.businessService.queryFeeMod(data);
    }
    @Post('feemodelecreate')
    async createfeemodele(@Body() data: FeeModEleDto) {
        return await this.businessService.createFeeModEle(data);
    }
    @Post('feemodeleupdate')
    async updatefeemodele(@Body() data: UpdateFeeModEleDto) {
        return await this.businessService.updateFeeModEle(data);
    }
    @Post('feemodeledelete')
    async deletefeemodele(@Body() data: DeleteStrPrimaryDto) {
        return await this.businessService.deleteFeeModEle(data);
    }
    @Post('feemodelequery')
    async queryfeemodele(@Body() data: SqlQueryDto) {
        return await this.businessService.queryFeeModEle(data);
    }
    @Post('feecodcreate')
    async createfeecod(@Body() data: FeeCodDto) {
        return await this.businessService.createFeeCod(data);
    }

    @Post('feecodupdate')
    async updatefeecod(@Body() data: UpdateFeeCodDto) {
        return await this.businessService.updateFeeCod(data);
    }

    @Post('feecoddelete')
    async deletefeecod(@Body() data: DeleteStrPrimaryDto) {
        return await this.businessService.deleteFeeCod(data);
    }

    @Post('feecodquery')
    async queryfeecod(@Body() data: SqlQueryDto) {
        return await this.businessService.queryFeeCod(data);
    }
    @Post('feetypcreate')
    async createfeetyp(@Body() data: FeeTypDto) {
        return await this.businessService.createFeeTyp(data);
    }

    @Post('feetypupdate')
    async updatefeetyp(@Body() data: UpdateFeeTypDto) {
        return await this.businessService.updateFeeTyp(data);
    }

    @Post('feetypdelete')
    async deletefeetyp(@Body() data: DeleteStrPrimaryDto) {
        return await this.businessService.deleteFeeTyp(data);
    }

    @Post('feetypquery')
    async queryfeetyp(@Body() data: SqlQueryDto) {
        return await this.businessService.queryFeeTyp(data);
    }
    @Post('feecodmodcreate')
    async createfeecodmod(@Body() data: FeeCodModDto) {
        return await this.businessService.createFeeCodMod(data);
    }
    @Post('feecodmodupdate')
    async updatefeecodmod(@Body() data: UpdateFeeCodModDto) {
        return await this.businessService.updateFeeCodMod(data);
    }
    @Post('feecomoddelete')
    async deletefeecodmod(@Body() data: DeleteStrPrimaryDto) {
        return await this.businessService.deleteFeeCodMod(data);
    }
    @Post('feecodmodquery')
    async queryfeecodmod(@Body() data: SqlQueryDto) {
        return await this.businessService.queryFeeCodMod(data);
    }
    @Post('feetypcodupdate')
    async updatefeetypcod(@Body() data: UpdateFeeTypCodDto) {
        return await this.businessService.updateFeeTypCod(data);
    }
    @Post('feecodquerybyfeetyp')
    async queryfeecodbyfeetyp(@Body('feetyp') feetyp: string) {
        return await this.businessService.getFeeCodByFeeTyp(feetyp);
    }
    @Post('protocolratecreate')
    async createprotocolrate(@Body() data: ProtocolRatDto) {
        return await this.businessService.createProtocolRate(data);
    }

    @Post('protocolrateupdate')
    async updateprotocolrate(@Body() data: UpdateProtocolRateDto) {
        return await this.businessService.updateProtocolRate(data);
    }

    @Post('protocolratedelete')
    async deleteprotocolrate(@Body() data: DeleteDto) {
        return await this.businessService.deleteProtocolRate(data);
    }

    @Post('protocolratequery')
    async queryprotocolrate(@Body() data: SqlQueryDto) {
        return await this.businessService.queryProtocolRate(data);
    }
    @Post('categorycreate')
    async createcategory(@Body() data: CategoryDto) {
        return await this.businessService.createCategory(data);
    }

    @Post('categoryupdate')
    async updatecategory(@Body() data: UpdateCategoryDto) {
        return await this.businessService.updateCategory(data);
    }

    @Post('categorydelete')
    async deletecategory(@Body() data: DeleteDto) {
        return await this.businessService.deleteCategory(data);
    }

    @Post('categoryquery')
    async querycategory(@Body() data: SqlQueryDto) {
        return await this.businessService.queryCategory(data);
    }
    @Post('categorysurplusquery')
    async querysurpluscategory(@Body() data: SqlQueryDto) {
        return await this.businessService.queryCategorySurplus(data);
    }
    @Post('exchangeratecreate')
    async createexchangerate(@Body() data: ExchangeRateDto) {
        return await this.businessService.createExchangeRate(data);
    }
    @Post('exchangerateupdate')
    async updateexchangerate(@Body() data: UpdateExchangeRateDto) {
        return await this.businessService.updateExchangeRate(data);
    }
    @Post('exchangeratedelete')
    async deleteexchangerate(@Body() data: DeleteStrPrimaryDto) {
        return await this.businessService.deleteExchangeRate(data);
    }
    @Post('exchangeratequery')
    async queryexchangerate(@Body() data: SqlQueryDto) {
        return await this.businessService.queryExchangeRate(data);
    }
    @Post('currencycreate')
    async createcurrency(@Body() data: CurrencyDto) {
        return await this.businessService.createCurrency(data);
    }

    @Post('currencyupdate')
    async updatecurrency(@Body() data: UpdateCurrencyDto) {
        return await this.businessService.updateCurrency(data);
    }

    @Post('currencydelete')
    async deletecurrency(@Body() data: DeleteStrPrimaryDto) {
        return await this.businessService.deleteCurrency(data);
    }

    @Post('currencyquery')
    async querycurrency(@Body() data: SqlQueryDto) {
        return await this.businessService.queryCurrency(data);
    }
    @Post('paycreate')
    async createpay(@Body() data: PayDto, @Session() session: Record<string, any>) {
        
        return await this.businessService.createPay(data, session['user']['name']);
    }

    @Post('payupdate')
    async updatepay(@Body() data: UpdatePayDto, @Session() session: Record<string, any>) {
        return await this.businessService.updatePay(data, session['user']['name']);
    }

    @Post('paydelete')
    async deletepay(@Body() data: DeleteDto) {
        return await this.businessService.deletePay(data);
    }

    @Post('payquery')
    async querypay(@Body() data: SqlQueryDto) {
        return await this.businessService.queryPay(data);
    }
    @Post('prepaycreate')
    async createprepay(@Body() data: PrePayDto, @Session() session: Record<string, any>) {
        data.fee_nam = session['user']['name'];
        return await this.businessService.createPrePay(data);
    }

    @Post('prepayupdate')
    async updateprepay(@Body() data: UpdatePrePayDto) {
        return await this.businessService.updatePrePay(data);
    }

    @Post('prepaydelete')
    async deleteprepay(@Body() data: DeleteDto) {
        return await this.businessService.deletePrePay(data);
    }

    @Post('prepayquery')
    async queryprepay(@Body() data: SqlQueryDto) {
        return await this.businessService.queryPrePay(data);
    }
    @Post('prepayback')
    async backprepay(@Body() data: DeleteDto) {
        return await this.businessService.backPrePay(data);
    }
    @Post('transprepay')
    async transprepay(@Body() data: DeleteDto) {
        return await this.businessService.transPrePay(data);
    }
    @Post('auditpayandfeedetquery')
    async queryauditpay(@Body() data: SqlQueryDto) {
        
        
        return await this.businessService.queryAuditPayAndFeedet(data);
    }
    @Post('queryVPreAuditInvoicePay')
    async queryVPreAuditInvoicePay(@Body() data: SqlQueryDto) {
        return await this.businessService.queryVPreAuditInvoicePay(data);
    }
    @Post('queryVPreAuditInvoiceFeedet')
    async queryVPreAuditInvoiceFeedet(@Body() data: SqlQueryDto) {
        return await this.businessService.queryVPreAuditInvoiceFeedet(data);
    }
    @Post('getmodsbyfeecod')
    async querymodsbyfeecod(@Body() data: queryModsByFeeCodDto) {
        return await this.businessService.queryModsByFeeCods(data);
    }
    @Post('getelesbyfeemod')
    async queryelesbyfeemod(@Body() data: queryElesByFeeModDto) {
        return await this.businessService.queryElesByFeeMod(data);
    }
    @Post('feedetcreate')
    async createfeedet(@Body() data: FeedetDto, @Session() session: Record<string, any>) {
        data.fee_nam = session['user']['name'];
        return await this.businessService.createFeedet(data);
    }
    @Post('feedetupdate')
    async updatefeedet(@Body() data: UpdateFeedetDto) {
        return await this.businessService.updateFeedet(data);
    }
    @Post('feedetdelete')
    async deletefeedet(@Body() data: DeleteDto) {
        return await this.businessService.deleteFeedet(data);
    }
    @Post('feedetquery')
    async queryFeedet(@Body() data: SqlQueryDto, @Session() session: Record<string, any>) {
        return await this.businessService.queryFeedet(data, session['user']);
    }
    @Post('monthfeecreate')
    async createmonthfee(@Body('month') month: Date, @Session() session: Record<string, any>) {
        return await this.businessService.createMonthFee(month, session['user']['name']);
    }
    @Post('monthfeedelete')
    async deletemonthfee(@Body('month') month: Date) {
        return await this.businessService.cancelMonthFee(month);
    }
    @Post('auditgroupquery')
    async queryauditgroup(@Body() data: SqlQueryDto) {
        return await this.businessService.queryAuditGroup(data);
    }
    @Post('auditdetailquery')
    async queryauditdetail(@Body() data: SqlQueryDto) {
        return await this.businessService.queryAuditDetail(data);
    }
    @Post('audit')
    async audit(@Body() dto: AuditDto) {
        return await this.businessService.audit(dto);
    }
    @Post('auditinvoicepay')
    async auditinvoicepay(@Body() dto: AuditInvoicePayDto) {
        return await this.businessService.auditInvoicePay(dto);
    }
    @Post('auditinvoicefeedet')
    async auditinvoicefeedet(@Body() dto: AuditInvoiceFeedetDto) {
        return await this.businessService.auditInvoiceFeedet(dto);
    }
    @Post('auditdelete')
    async deleteaudit(@Body() data: DeleteStrPrimaryDto) {
        return await this.businessService.cancelAudit(data);
    }
    @Post('invoicecreate')
    async createinvoice(@Body() data: InvoiceDto) {

        return await this.businessService.createInvoice(data);
    }

    @Post('invoiceupdate')
    async updateinvoice(@Body() data: UpdateInvoiceDto) {
        return await this.businessService.updateInvoice(omit(data, ['tax_amount', 'amount']) as UpdateInvoiceDto);
    }

    @Post('invoicedelete')
    async deleteinvoice(@Body() data: DeleteDto) {
        return await this.businessService.deleteInvoice(data);
    }

    @Post('invoicequery')
    async queryinvoice(@Body() data: SqlQueryDto) {
        return await this.businessService.queryInvoice(data);
    }
    
    @Post('auditinvoicepaygroupquery')
    async queryauditinvoicepaygroup(@Body() data: SqlQueryDto) {
        return await this.businessService.queryVAuditInvoicePayGroup(data);
    }
    @Post('auditinvoicepaydetailquery')
    async queryauditinvoicepaydetail(@Body() data: SqlQueryDto) {
        return await this.businessService.queryVAuditInvoicePayDetail(data);
    }

    @Post('auditInvoicePaydelete')
    async deleteauditinvoicepay(@Body() data: DeleteStrPrimaryDto) {
        return await this.businessService.cancelAuditInvoicePay(data);
    }
    @Post('auditinvoicefeedetgroupquery')
    async queryauditinvoicefeedetgroup(@Body() data: SqlQueryDto) {
        return await this.businessService.queryVAuditInvoiceFeedetGroup(data);
    }
    @Post('auditinvoicefeedetdetailquery')
    async queryauditinvoicefeedetdetail(@Body() data: SqlQueryDto) {
        return await this.businessService.queryVAuditInvoiceFeedetDetail(data);
    }

    @Post('auditInvoicefeedetdelete')
    async deleteauditinvoicefeedet(@Body() data: DeleteStrPrimaryDto) {
        return await this.businessService.cancelAuditInvoiceFeedet(data);
    }

    @Post('feedetreport')
    async feedetreport(@Body() dto: BusiReportDto) {
        return await this.businessService.FeedetReport(dto);
    }

    /**
     * 银行存款明细表
     * @param dto 
     * @returns 
     */
    @Post('categoryreport')
    async categoryreport(@Body() dto: BusinessReportDto) {
        return await this.businessService.categoryReport(dto);
    }
    /**
     * 银行存款流水表
     * @param dto 
     * @returns 
     */
    @Post('categorydetailreport')
    async categorydetailreport(@Body() dto: BusinessReportDto) {
        return await this.businessService.categoryDetailReport(dto);
    }
    /**
     * 成本费用明细表
     * @param dto 
     * @returns 
     */
    @Post('feedetoutreport')
    async feedetoutreport(@Body() dto: BusinessReportDto) {
        return await this.businessService.feedetoutReport(dto);
    }

    /**
     * 资产类往来明细表
     * @param dto 
     * @returns 
     */
    @Post('assetclassreport')
    async assetclassreport(@Body() dto: BusinessReportDto) {
        return await this.businessService.assetClassReport(dto, 'A');
    }

    /**
     * 负债类往来明细表
     * @param dto 
     * @returns 
     */
    @Post('liabilityclassreport')
    async liabilityclassreport(@Body() dto: BusinessReportDto) {
        return await this.businessService.assetClassReport(dto, 'L');
    }

    @UsePipes(new ValidationPipe({whitelist: true}))
    @Post('feedetecharts')    
    async feedetEcharts(@Body() dto: BusiReportDto) {
        return await this.businessService.feedetEcharts(dto);
    }

    @UsePipes(new ValidationPipe({whitelist: true}))
    @Post('feereportcfgquery')
    async feereportcfgquery() {
        return await this.businessService.feeReportDefineQuery();
    }

    @UsePipes(new ValidationPipe({whitelist: true}))
    @Post('feereportcfgcreate')
    async feereportcfgcreate(@Body() dto: FeeReportDefineDto) {
        return await this.businessService.feeReportDefineCreate(dto);
    }

    @UsePipes(new ValidationPipe({whitelist: true}))
    @Post('feereportcfgupdate')
    async feereportcfgupdate(@Body() dto: UpdateFeeReportDefineDto) {
        return await this.businessService.feeReportDefineUpdate(dto);
    }

    @Post('feereportcfgdelete')
    async feereportcfgdelete(@Body() dto: DeleteDto) {
        return await this.businessService.feeReportDefineDelete(dto);
    }

    @Post('feereportqueryfeecods')
    async feereportqueryfeecods(@Body() dto: {r_name: string}) {
        return await this.businessService.getFeeCodsFromFeeReport(dto.r_name);
    }

    @Post('leasefeereport')
    async leasefeereport(@Body() dto: LeaseFeeReportDto) {
        return await this.businessService.leaseFeeReport(dto);
    }

    @Post('leasefeeusdinvoice')
    async leasefeeusdinvoice(@Body() dto: LeaseFeeUsdInvoiceDto) {
        return await this.businessService.leaseFeeInvoice(dto);
    }

    @Post('cfsfeereport')
    async cfsfeereport(@Body() dto: LeaseFeeReportDto) {
        return await this.businessService.cfsFeeReport(dto);
    }
}
